package com.nd.android.u.ui.activity.message_chat;

import ims.utils.IMLogUtils;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.nd.android.u.controller.ChatConst.KEY;
import com.nd.android.u.controller.ChatConst.LocalMessageType;
import com.nd.android.u.controller.factory.AppMessageFactory;
import com.nd.android.u.ui.ChatEntry;
import com.nd.android.u.ui.R;
import com.nd.android.u.ui.activity.chat_config.DeleteHistoryDialog;
import com.nd.android.u.ui.beanStarApp.DisplayMessage_App;

import de.greenrobot.event.EventBus;

/**
 * 应用消息界面
 * <br>Created 2014-7-23 下午2:19:54
 * @version  
 * @author   cb		
 * @see 	 
 */
public class ChatActivity_App extends BaseChatMessageActivity{
	/**删除历史记录对话框*/
	private DeleteHistoryDialog mDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		EventBus.getDefault().register(this, View.class);
	}

	@Override
	protected void onDestroy() {
		EventBus.getDefault().unregister(this, View.class);
		super.onDestroy();
	}

	@Override
	protected boolean getParam(Bundle bundle) {
		messageType=LocalMessageType.APP;
		generalId=bundle.getInt(KEY.APPID);
        if (generalId==0){
        	IMLogUtils.e(IMLogUtils.CHAT,"appid is 0");
        	finish();
        	return false;
        }
        appcode=bundle.getString(KEY.APPCODE);
        if (TextUtils.isEmpty(appcode)){
        	IMLogUtils.e(IMLogUtils.CHAT,"appcode is null");
        	finish();
        	return false;
        }
        if (TextUtils.isEmpty(name)){
        	DisplayMessage_App app=(DisplayMessage_App) AppMessageFactory.INSTANCE.getAppMessage((int) generalId, appcode);
        	if (app!=null){
        		name=app.getAppName(this);
        	}else{
        		name=ChatEntry.INSTANCE.chatCallOtherModel_UI.getAppName((int) generalId, appcode);
        	}
        }
		return true;
	}
	
	@Override
	protected int getRightButtonRes() {
		return R.drawable.delete_title_bg;
	}
	
	@Override
	public void rightBtnHandle() {
		if (mDialog==null){
			DisplayMessage_App message=new DisplayMessage_App();
			message.appId=(int) generalId;
			message.appCode=appcode;
			mDialog=new DeleteHistoryDialog(this, message);
		}
		mDialog.show();
	}
	
	
	/**
	 * 重绘界面后的通知
	 * 
	 * <br>
	 * Created 2014-11-4 上午11:13:29
	 * 
	 * @param obj
	 * @author : HuangYK
	 */
	public void onEventMainThread(View view) {
		mMessageListFragment.scrollToBottom(true);
	}
}
